package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.domain.TbClue;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 *
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    @Autowired
    private TbBusinessMapper tbBusinessMapper;

    /**
     * 新增商机跟进记录
     */
    @Override
    public int add(BusinessTrackVo businessTrackVo) {
        //创建商机跟进实体类
        TbBusinessTrackRecord trackRecord = new TbBusinessTrackRecord();
        //将前端传来的基础数据复制到商机跟进实体类中
        BeanUtils.copyProperties(businessTrackVo, trackRecord);
        trackRecord.setCreateTime(DateUtils.getNowDate());
        trackRecord.setCreateBy(SecurityUtils.getUsername());

        //创建商机实体类对象
        TbBusiness tbBusiness = new TbBusiness();
        //将基本数据复制到商机实体类对象
        BeanUtils.copyProperties(businessTrackVo, tbBusiness);
        tbBusiness.setId(businessTrackVo.getBusinessId());
        tbBusiness.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        //进行商机信息更新
        tbBusinessMapper.updateTbBusiness(tbBusiness);

        return tbBusinessTrackRecordMapper.add(trackRecord);
    }


    /**
     * 查询商机跟进记录列表
     */
    @Override
    public List<TbBusinessTrackRecord> list(Long id) {
        return tbBusinessTrackRecordMapper.list(id);
    }
}
